<script setup lang="ts">
import { ref, defineProps, defineEmits } from 'vue'
import { ElMessage } from 'element-plus'
import { updateProcureApi } from '@/apis/order'

interface Props {
  visible: boolean,
  info: any
}

const props = defineProps<Props>()
const emit = defineEmits(['confirm', 'update:visible'])

const formData = ref({
  ch_order_track_num: ''
})

watch(() => props.info, (val) => {
  formData.value = {
    ch_order_track_num: val.ch_order_track_num
  }
})

/** 关闭弹窗 */
const handleClose = () => {
  formData.value = {
    ch_order_track_num: ''
  }
  emit('update:visible', false)
  console.log('关闭')
}

const handleConfirm = async () => {
  const res = await updateProcureApi({...props.info, ...formData.value})
  ElMessage.success(res.msg)
  emit('confirm')
  handleClose()
}
</script>

<template>
  <el-dialog :model-value="visible" title="编辑发货信息" width="500" @close="handleClose">
    <!-- 对话框内容插槽 -->
    <el-form label-width="80" label-position="left">
      <el-form-item label="快递单号">
        <el-input v-model="formData.ch_order_track_num" placeholder="请输入快递单号" />
      </el-form-item>
    </el-form>

    <!-- 自定义底部按钮 -->
    <template #footer>
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="handleConfirm">确定</el-button>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped></style>
